﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApCableNameTextControl
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Markup;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands;

public class CApCableNameTextControl : 
  UserControl,
  ICApFLEXCableEditorSelection,
  IDisposable,
  IComponentConnector
{
  private bool m_isControlLoading;
  private ICApCableNameViewModel m_nameViewModel;
  internal TxObjEditBoxControl m_editBox;
  private bool _contentLoaded;

  public CApCableNameTextControl()
  {
    this.InitializeComponent();
    this.m_isControlLoading = true;
  }

  public void Dispose()
  {
    this.m_nameViewModel.PropertyChanged -= new PropertyChangedEventHandler(this.NameViewModel_PropertyChanged);
  }

  public void InitializeControl(ICApCableNameViewModel nameViewModel)
  {
    this.m_nameViewModel = nameViewModel ?? throw new ArgumentNullException(nameof (nameViewModel));
    this.m_editBox.SetValidator((ITxValidator) new CApFLEXCableValidator((ICApFLEXCableEditorSelection) this));
    this.m_nameViewModel.PropertyChanged += new PropertyChangedEventHandler(this.NameViewModel_PropertyChanged);
  }

  public void EndOfLoading()
  {
    this.m_isControlLoading = false;
    this.m_editBox.Text = this.m_nameViewModel.CableName;
  }

  public bool ShouldDisplayCableEditorEmptyToolTip() => !this.m_isControlLoading;

  private void EditBox_KeyUp(object sender, KeyEventArgs e)
  {
    this.m_nameViewModel.CableName = this.m_editBox.Text;
  }

  private void NameViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
    if (!(e.PropertyName == "CableName") || !(this.m_editBox.Text != this.m_nameViewModel.CableName))
      return;
    this.m_editBox.Text = this.m_nameViewModel.CableName;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/flexibles/editboxcontrols/capcablenametextcontrol.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    if (connectionId == 1)
    {
      this.m_editBox = (TxObjEditBoxControl) target;
      ((UIElement) this.m_editBox).KeyUp += new KeyEventHandler(this.EditBox_KeyUp);
    }
    else
      this._contentLoaded = true;
  }
}
